cmake_minimum_required(VERSION 3.25)
project(iriscc)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Set output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)


include_directories(include)

# ANTLR
set(ANTLR_EXECUTABLE "${PROJECT_SOURCE_DIR}/binary/antlr-4.13.2-complete.jar")
set(ANTLR_RUNTIME "${PROJECT_SOURCE_DIR}/antlr")

set(ANTLR4_INSTALL ON)
set(ANTLR_BUILD_CPP_TESTS OFF) # Only for ANTLR 4.10.0 and later versions
add_subdirectory(${ANTLR_RUNTIME})

#set(ANTLR_INCLUDE_DIRECTORY_BINARY "${CMAKE_CURRENT_BINARY_DIR}/src" CACHE STRING "Include dirs for antlr")

# LLVM

find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_PATH}")

message("Found LLVM ${LLVM_PACKAGE_VERSION}, build type ${LLVM_BUILD_TYPE}")

list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})

include(AddLLVM)
include(HandleLLVMOptions)

include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_INCLUDE_DIRS}")
link_directories("${LLVM_LIBRARY_DIR}")

set(IRISCC_BUILT_STANDALONE 1)

include_directories("${ANTLR_RUNTIME}/runtime/src")

add_subdirectory(lib)
add_subdirectory(tools)
